﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.SoldierArchives.BLL;

public partial class Police_TranslateDocument_TranslatePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //TranslateInfo translateInfo = Translate.GetDetail(new Guid(Request["Fid"]));
        TranslateLogInfo translateLog = TranslateLogs.GetLastDetail(new Guid(Request["Fid"]));
        //士兵调动操作
        TranslateIntroLetterInfo info = TranslateIntroLetter.GetDetail(translateLog.DID);
        string transferID = "";
        if (!String.IsNullOrEmpty(Request["TID"]))
            transferID = Request["TID"];
        string UserName = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName;
        TranslateInfo Info = Translate.GetDetail(new Guid(Request.QueryString["Fid"].ToString()));

        Guid Trid = Guid.Empty;
        if (Info.TID == 1)//调入
        {
            Trid = TransferSoldier.Transfer(Info.SID.ToString(), Info.FromDepartmentID, Info.OldDepartment, Info.ToDepartmentID, Info.NewDepartment, Convert.ToDateTime(DateTranslate.Text), User.Identity.Name, UserName, DateTime.Now, Info.FromJingZhong, Info.ToJingZhong, info.DateRegister, info.ApproveMan, "");
            if (Trid != Guid.Empty)
            {
                Soldier soldier = new Soldier();
                SoldierArchiveInfo soldierInfo = soldier.GetSoldierInfoByID(Info.SID.ToString());
                soldierInfo.DepartmentID = Info.ToDepartmentID;
                soldier.Update(soldierInfo, User.Identity.Name, Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName);
            }
            else
            {
                Prompt.Text = "提示：调动失败！";
            }
        }
        else if (Info.TID == 2)//调出
        {
            Trid = TransferSoldier.Transfer(Info.SID.ToString(), Info.FromDepartmentID, Info.OldDepartment2, Info.ToDepartmentID, Info.NewDepartment, Convert.ToDateTime(DateTranslate.Text), User.Identity.Name, UserName, DateTime.Now, Info.FromJingZhong, Info.ToJingZhong, info.DateRegister, info.ApproveMan, "");
            if (Trid != Guid.Empty)
            {
                Soldier soldier = new Soldier();
                soldier.Delete(Info.SID.ToString(), "调离", DateTime.Now, User.Identity.Name, Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName);
            }
        }
        else if (Info.TID == 3)//内调
        {
            Trid = TransferSoldier.Transfer(Info.SID.ToString(), Info.FromDepartmentID, Info.OldDepartment2, Info.ToDepartmentID, Info.NewDepartment, Convert.ToDateTime(DateTranslate.Text), User.Identity.Name, UserName, DateTime.Now, Info.FromJingZhong, Info.ToJingZhong, info.DateRegister, info.ApproveMan, "");
            if (Trid != Guid.Empty)
            {
                Soldier soldier = new Soldier();
                SoldierArchiveInfo soldierInfo = soldier.GetSoldierInfoByID(Info.SID.ToString());
                soldierInfo.DepartmentID = Info.ToDepartmentID;
                soldier.Update(soldierInfo, User.Identity.Name, Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName);
            }
        }

        TranslateLogInfo log = new TranslateLogInfo();
        log.DID = Trid;
        log.FID = new Guid(Request["FID"]);
        log.LastTime = DateTime.Now;
        TranslateInfo TInfo = Translate.GetDetail(new Guid(Request["Fid"]));
        log.PID = TranslateProcess.GetNextDetail(TranslateLogs.GetLastDetail(TInfo.ID).PID).ID;
        TranslateLogs.Insert(log);
        Response.Redirect("../TranslateProcess/ProcessList.aspx");
    }
}
